package com.lz.dubbo.producer.common.exception;

import com.lz.dubbo.producer.common.domain.ErrMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    //结果标识 0：正常  其他：异常
    private Integer errorCode;
    //错误信息
    private String errorMsg;
    /**
     * 错误提示
     */
    private String code;
    /**
     * 错误提示
     */
    private String message;

    private boolean success;
    //请求参数
    private Object request;
    //返回结果
    private Object result;
    //自定义返回参数1
    private String point;
    //自定义返回参数2
    private String sole;
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    public ServiceException() {
    }

    public ServiceException(String errorMsg) {
        this.errorMsg = errorMsg;
        this.message = errorMsg;
        this.logger.error("错误信息：{0}", errorMsg);
    }

    public ServiceException(String errorMsg, Integer errorCode) {
        this.errorMsg = errorMsg;
        this.errorCode = errorCode;
        this.logger.error("错误码：{0}，错误信息：{1}", errorCode, errorMsg);
    }

    public ServiceException(ErrMsg errMsg) {
        this.errorMsg = errMsg.getErrorMsg();
        this.errorCode = errMsg.getErrorCode();
        this.logger.error("错误码：{0}，错误信息：{1}", this.errorCode, this.errorMsg);
    }

    public ServiceException(ErrMsg errMsg, String strackMsg) {
        this.errorMsg = errMsg.getErrorMsg() + " " + strackMsg;
        this.errorCode = errMsg.getErrorCode();
        this.logger.error("错误码：{0}，错误信息：{1}", this.errorCode, this.errorMsg);
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public Integer getErrorCode() {
        return this.errorCode;
    }

    public ServiceException setMessage(String errorMsg) {
        this.errorMsg = errorMsg;
        return this;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
